package com.mzj.saas.mservice.bill.mapper;

import com.mzj.saas.commons.DateUtils;
import com.mzj.saas.commons.util.ConvertUtils;
import com.mzj.saas.mservice.bill.vo.ExpenseBillListVO;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ExpenseBillRowMapper implements RowMapper<ExpenseBillListVO> {
    @Override
    public ExpenseBillListVO mapRow(ResultSet rs, int rowNum) throws SQLException {
        ExpenseBillListVO vo = new ExpenseBillListVO();
        vo.setId(rs.getLong("id"));
        vo.setHouseId(rs.getString("houseId"));
        vo.setCommunityId(rs.getString("communityId"));
        vo.setBuildingNum(rs.getLong("buildingNum"));
        vo.setUnit(rs.getLong("unit"));
        vo.setRoomNumber(rs.getString("roomNumber"));
        vo.setMatchUserId(rs.getString("matchUserId"));
        vo.setChargeType(rs.getInt("chargeType"));
        vo.setMeasureUnit(rs.getString("measureUnit"));
        Integer chargeType = vo.getChargeType();
        switch (chargeType) {
            case 1:
                vo.setStartNum(rs.getInt("waterStartNum"));
                vo.setEndNum(rs.getInt("waterEndNum"));
                vo.setUsage(rs.getInt("waterUsage"));
                vo.setUnitPrice(ConvertUtils.fenConvertYuan(rs.getInt("waterUnitPrice")));
                break;
            case 2:
                vo.setStartNum(rs.getInt("electricStartNum"));
                vo.setEndNum(rs.getInt("electricEndNum"));
                vo.setUsage(rs.getInt("electricUsage"));
                vo.setUnitPrice(ConvertUtils.fenConvertYuan(rs.getInt("electricUnitPrice")));
                break;
            case 6:
                vo.setStartNum(rs.getInt("gasStartNum"));
                vo.setEndNum(rs.getInt("gasEndNum"));
                vo.setUsage(rs.getInt("gasUsage"));
                vo.setUnitPrice(ConvertUtils.fenConvertYuan(rs.getInt("gasUnitPrice")));
                break;
        }
        vo.setCost(ConvertUtils.fenConvertYuan(rs.getInt("cost")));//分转元
        vo.setStartTime(DateUtils.format(rs.getDate("startTime"), DateUtils.FORMAT_DATE_8));
        vo.setEndTime(DateUtils.format(rs.getDate("endTime"), DateUtils.FORMAT_DATE_8));
        vo.setPaymentStatus(rs.getInt("paymentStatus"));
        vo.setShouldPayTime(DateUtils.format(rs.getDate("shouldPayTime"), DateUtils.FORMAT_DATE_8));
        return vo;
    }


}
